package com.woniuxy.web.handler;

import com.woniuxy.core.exception.PawnException;
import com.woniuxy.core.util.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常拦截器
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 拦截自定义异常
     * @param e
     * @return
     */
    @ExceptionHandler(PawnException.class)
    public Result handlerPawnException(PawnException e){
        return Result.fail(e.getCode(),e.getMessage());
    }

    /**
     * 拦截最大异常兜底
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    public Result handlerBuildingException(Exception e){
        e.printStackTrace();
        return Result.fail(500,e.getMessage());
    }
}

